﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Obligatorio2013.Modelo;
using Obligatorio2013.Clases;
using System.Web.Security;

namespace Obligatorio2013.Pages.Cuenta
{
    public partial class LoginForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        {

            bool Autenticado = false;
            Autenticado = LoginCorrecto(Login1.UserName, Login1.Password);
            e.Authenticated = Autenticado;
            if (Autenticado)
            {
                //Response.Redirect("Default.aspx");
                FormsAuthentication.RedirectFromLoginPage(Login1.UserName, Login1.RememberMeSet);
            }
            else
            {

            }
        }
        private bool LoginCorrecto(string Usuario, string Contrasena)
        {
            Sistema sistem = Sistema.Instance;

            Users usr = sistem.login(Usuario, Contrasena);
            if (usr != null)
            {
                Session["user"] = usr.ToString();
                Session["userRole"] = usr.UserRole;
                Session["logged"] = true;
                Session["aserStatus"] = usr.UserActive;

                return true;
            }
            return false;
        }
    }
}